import { LayaPoolName } from "../LayaPoolName";
import MonsterData from "../data/MonsterData";
import Game from "../Game";
import MonsterScript from "../../component/MonsterScript";
 

export default class Monster {

    private _poolIndex = [];

    private _dieEffectRecoverTime: number = 60 * 1.5;

    private _poolSp = [];

 

    public reset() {
        this._poolIndex.map((p) => {
            Laya.Pool.clearBySign(p);
        });
        this._poolSp.map((s)=>{
           s.destroy();
        })
        this._poolSp=[];
        this._poolIndex = [];
    }

   

    public getMonster(monsterData: MonsterData): Laya.MeshSprite3D {
        // console.log("getMonster",monsterData)
        let monster: Laya.Sprite3D = Laya.Pool.getItem(LayaPoolName.MONSTER + monsterData.id);
        let monsterScript: MonsterScript;
        if (monster == null) {
            monster = Laya.Sprite3D.instantiate(Laya.loader.getRes(monsterData.resPath)) as Laya.Sprite3D;
            Game.monsterResClones.push(monster);
            this._poolIndex.push(LayaPoolName.MONSTER + monsterData.id);

            // let collider: Laya.PhysicsCollider = ((monster.getChildAt(0) as Laya.MeshSprite3D).getComponent(Laya.PhysicsCollider));
            // console.log(collider)
            // collider.collisionGroup = GameCollisionGroup.MONSTER;
            // console.log(monster)
            monsterScript = monster.getChildAt(0).addComponent(MonsterScript);
            monsterScript.init(monsterData);
 
            this._poolSp.push(monsterScript);
        }
        // console.log(monster)
        if (monsterScript == null) {
            // console.log(monster)
            monsterScript = monster.getComponent(MonsterScript);
            monsterScript.reset();
            return monster as Laya.MeshSprite3D;
        }
        else {
            // monsterScript.reset();
            return monster.getChildAt(0) as Laya.MeshSprite3D;
        }
    }

  

}